/*
 * @Author: lxj l18762185937@163.com
 * @Date: 2022-09-16 08:53:59
 * @LastEditors: lxj lxj1008007@163.com
 * @LastEditTime: 2022-09-16 20:50:57
 * @FilePath: \9.16李雪军作业\my-work\vue.config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const { defineConfig } = require('@vue/cli-service')
const Mock = require('mockjs')

const data = Mock.mock({
  'list|100': [
    {
      img: '@image(70x70,@color,@cname)',
      name: '@cname',
      title: '@ctitle',
      id: '@id',
      city: '@city',
    },
  ],
})

module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    setupMiddlewares: (middlewares, { app }) => {
      app.get('/api/list', (req, res) => {
        const { pageCode = 1, pageSlize = 10 } = req.query
        console.log(pageCode, pageSlize)
        res.send({
          code: 200,
          data: data.list.slice(
            (pageCode - 1) * pageSlize,
            pageCode * pageSlize
          ),
          length: data.list.length,
        })
      })
      return middlewares
    },
  },
})
